import request from '@/utils/request'

// 获取编码规则列表
export function getSerialRuleList(data) {
    return request({
        url: '/serialRule/getSerialRuleList',
        method: 'post',
        data: data
    })
}

// 添加编码规则
export function addSerialRule(data) {
    return request({
        url: '/serialRule/addSerialRule',
        method: 'post',
        data: data
    })
}

// 编码规则详情
export function getSerialRuleByNum(data) {
    return request({
        url: '/serialRule/getSerialRuleByNum',
        method: 'post',
        data: data
    })
}

// 编码规则状态
export function setSerialRuleStatusByIdArr(data) {
    return request({
        url: '/serialRule/setSerialRuleStatusByIdArr',
        method: 'put',
        data: data
    })
}

// 获取编号规则
export function getSerialRuleByMenuId(data) {
    return request({
        url: '/serialRule/getSerialRuleByMenuId',
        method: 'post',
        data: data
    })
}


// 根据编码名称获取编码
export function getSerialRuleByName(data) {
    return request({
        url: '/serialRule/getSerialValueByName/'+data,
        method: 'get'
    })
}


// 文件上传
export function uploadFile(data) {
    if (data.get('type') == null) {
        data.append('type', 0)
    }
    return request({
        url: '/file/uploadFile',
        method: 'post',
        data: data
    })
}

// 获取字典值列表
export function getDictionaryValueListmore(data) {
    return request({
        url: '/dictionaryValue/getDictionaryWithDictionaryValueList',
        method: 'post',
        data: data
    })
}



export function getUserIP(onNewIP) {
    let MyPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
    let pc = new MyPeerConnection({
      iceServers: []
    });
    let noop = () => {
    };
    let localIPs = {};
    let ipRegex = /([0-9]{1,3}(.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g;
    let iterateIP = (ip) => {
      if (!localIPs[ip]) onNewIP(ip);
      localIPs[ip] = true;
    };
    pc.createDataChannel('');
    pc.createOffer().then((sdp) => {
        console.log("sdp",sdp)
      sdp.sdp.split('\n').forEach(function (line) {
        if (line.indexOf('candidate') < 0) return;
        line.match(ipRegex).forEach(iterateIP);
      });
      pc.setLocalDescription(sdp, noop, noop);
    }).catch((reason) => {
    });
    pc.onicecandidate = (ice) => {
      if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
    //   var ip_addr = ice.candidate.address
      console.log("ip_addr",ice.candidate)
    let ip_rule = /([0-9]{1,3}(.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g
    // var ip_addr = ip_rule.exec(ice.candidate.candidate)[1]
    var ip_addr = ice.candidate.candidate.match(ip_rule)[1]
    console.log("ip_addr==",ip_addr)
      ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
    };
  }



























